package com.example.controller;


import com.example.common.Result;
import com.example.service.OrderinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Random;


@RestController
@RequestMapping("/msg")
public class MessageController {

    @Autowired
    private JedisPool jedisPool;

    @RequestMapping("/code")
    public Result getCode(String phone){
        Random random = new Random();
        System.out.println("phone = " + phone);
        if (null !=phone){
            String redisCode="";
            for (int i = 0; i < 4; i++) {
                int rand = random.nextInt(10);
                redisCode +=rand;
            }
            jedisPool.getResource().setex(phone,60,redisCode +"");
            System.out.println("redisCode = " + redisCode);
            return Result.success();
        }

        return Result.error("50002","请输入手机号");
    }

}
